package gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.List;

import javax.swing.JPanel;

import model.Drawable;

@SuppressWarnings("serial")
public class Grass extends JPanel implements Draws {
	
	private int boardSize = 400;
	private int blockSize = 10;
	private List<Drawable> drawables;
	
	public Grass(int boardSize, int blockSize) {
		this.boardSize = boardSize;
		this.blockSize = blockSize;
		
		Dimension grounds = new Dimension(boardSize, boardSize);
		setPreferredSize(grounds);
		setBounds(new Rectangle(grounds));
		setBackground(Color.GREEN);
		setVisible(true);
	}
	
	@Override
	public void paint(Graphics g) {
		// TODO Auto-generated method stub
		//super.paint(g);
		g.clearRect(0, 0, boardSize, boardSize);
		if (drawables != null && drawables.size() > 0) {
			for (Drawable drawable : drawables) {
				System.out.println(drawable);
				for (Point seg : drawable.getLocations()) {
					System.out.println("Drawing: " + seg);
					g.setColor(drawable.getColor());
					g.drawRect((int)seg.getX(), (int)seg.getY(), blockSize, blockSize);
				}
			}
		}
	}

	/** {@inheritDoc} */
	public void draw(List<Drawable> drawables) {
		this.drawables = drawables;		
	}
}
